package com.earnings.okhttputils.utils.ui.activity;

import android.view.View;

import com.earnings.R;
import com.earnings.okhttputils.utils.User;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.god.Listener.GodOnClickListener;
import com.earnings.okhttputils.utils.https.CommonAccess;
import com.earnings.okhttputils.utils.https.HttpObjectCallback;
import com.earnings.okhttputils.utils.utils.CommonUtil;
import com.earnings.okhttputils.utils.utils.PayUtil;

/**
 * 升级绿心
 * Created by Administrator on 2017/5/11 0011.
 */

public class UpGreenActivity extends GodLeftHandBaseActivity implements GodOnClickListener {
    private int green_lv;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_upgreen;
    }

    @Override
    protected void init() {
        green_lv = Integer.parseInt(CommonUtil.getUser().getGreen_lv());
        setTopVisibility(R.id.top_xian_view, View.GONE);
        setTextColor(R.id.uptitle_tv, getResources().getColor(R.color.white));
        setHideTopView();
        setText(R.id.uptitle_tv, "升级绿心");
        setOnClickListener(this, R.id.up_highgreen_tv, R.id.up_supergreen_tv, R.id.upback_view);
        setGlideImagView(R.id.head_img, CommonUtil.getUser().getHead_pic());
        setText(R.id.name_tv, CommonUtil.getUser().getNickname());
        upui();

    }

    private void upui() {
        switch (green_lv) {
            //普通
            case 0:
                setBackgroundColor(R.id.bg_view, getResources().getColor(R.color.style));
                setText(R.id.subsidy_tv, "补贴速度：0.06元/天*绿心数");
                setText(R.id.lv_tv, "普通");
                break;
            //高级
            case 1:
                setBackgroundResource(R.id.bg_view, R.mipmap.yu_sjlxgj_background01);
                setClickable(R.id.up_highgreen_tv, false);
                setText(R.id.up_highgreen_tv, "加速升级中...");
                setText(R.id.subsidy_tv, "补贴速度：0.08元/天*绿心数");
                setBackgroundResource(R.id.up_highgreen_tv, R.drawable.upno_bg);
                setTextColor(R.id.up_highgreen_tv, getResources().getColor(R.color.up));
                setText(R.id.lv_tv, "高级");
                break;
            //超级
            case 2:
                setClickable(R.id.up_highgreen_tv, false);
                setClickable(R.id.up_supergreen_tv, false);
                setBackgroundResource(R.id.bg_view, R.mipmap.yu_sjlxgj_background01);
                setText(R.id.subsidy_tv, "补贴速度：0.1元/天*绿心数");
                setText(R.id.up_highgreen_tv, "已升级...");
                setTextColor(R.id.up_highgreen_tv, getResources().getColor(R.color.up));
                setText(R.id.up_supergreen_tv, "加速升级中...");
                setTextColor(R.id.up_supergreen_tv, getResources().getColor(R.color.up));
                setBackgroundResource(R.id.up_highgreen_tv, R.drawable.upno_bg);
                setBackgroundResource(R.id.up_supergreen_tv, R.drawable.upno_bg);
                setText(R.id.lv_tv, "超级");
                break;

        }

    }

    @Override
    public void OnClickListener(View view) {
        if (view.getId() == R.id.upback_view) finish();
        //高级绿心
        if (view.getId() == R.id.up_highgreen_tv) {
            new PayUtil(getContext(), "1000") {
                @Override
                public void onSuccess(String paytype, String info) {
                    loadUser();

                }
            }.showUpgrade();

        }
        //超级绿心
        if (view.getId() == R.id.up_supergreen_tv) {
            new PayUtil(getContext(), "3000") {
                @Override
                public void onSuccess(String paytype, String info) {
                    loadUser();

                }
            }.showUpgradeSuper();

        }
        setTitle("升级绿心");
        setTopViewBackgroundResource(getResources().getColor(R.color.top_blue));
        setTopImageResource(back_view, R.mipmap.nav_back02);
        setTopTextColor(title_tv, getResources().getColor(R.color.white));
        setTopVisibility(top_xian_view, View.GONE);


    }


    /*
        读取用户
         */
    public void loadUser() {
        CommonAccess<User> userAccess = new CommonAccess<User>(this);
        userAccess.setCallback(new HttpObjectCallback<User>(this) {
            @Override
            public void onSuccess(User object, String msg) {
                object.setToken(CommonUtil.getUser().getToken());
                CommonUtil.commitUser(object);
                green_lv = Integer.parseInt(CommonUtil.getUser().getGreen_lv());
                upui();
            }

            @Override
            public void onFail(int code, String msg) {

            }
        });
        userAccess.userLoadData();

    }


}
